package com.qianyu.project.mapper.provider.smj;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.ObjectUtils;

import java.util.Map;

public class smjProviderProvider {

    //获取班组信息
    public String providerList(IPage<Map<String, Object>> page, Map<String, String> params){
        return new SQL(){
            {
                SELECT("*");
                FROM(" provider_info pi ,provider_type pt");
                WHERE("pi.type=pt.id");
                if (!ObjectUtils.isEmpty(params.get("providertype"))){
                   WHERE("pi.type ='"+params.get("providertype")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("providerName"))){
                    WHERE("pi.provider_name ='"+params.get("providerName")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("address"))){
                    WHERE("pi.address ='"+params.get("address")+"'");
                }
            }
        }.toString();
    }

    //获取员工信息
    public String getEmp(IPage<Map<String, Object>> page, Map<String, String> params){
        return new SQL(){
            {
                SELECT("*");
                FROM("emp e");
                LEFT_OUTER_JOIN("dept d on e.dept_id=d.id");
                LEFT_OUTER_JOIN("post p on e.post_id=p.id");
                if (!ObjectUtils.isEmpty(params.get("name"))){
                    WHERE("e.name ='"+params.get("name")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("dept"))){
                    WHERE("d.dept_name ='"+params.get("dept")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("post"))){
                    WHERE("p.post_name='"+params.get("post")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("dept_id"))){
                    WHERE("p.id='"+params.get("dept_id")+"'");
                }
            }
        }.toString();
    }

    //获取合同信息
    public String getLaber(IPage<Map<String, Object>> page, Map<String, String> params){
        return new SQL(){
            {
                SELECT("lc.*,pi.project_name ,pi2.provider_name,e.name");
                FROM("labor_contract lc");
                LEFT_OUTER_JOIN("project_info pi on lc.p_id= pi.id");
                LEFT_OUTER_JOIN("provider_info pi2 on lc.labor_org_id = pi2.id");
                LEFT_OUTER_JOIN(" emp e on lc.contract_signatory = e.id");
                if (!ObjectUtils.isEmpty(params.get("id"))){
                    WHERE("lc.id ='"+params.get("id")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("contract_name"))){
                    WHERE("lc.contract_name ='"+params.get("contract_name")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("start_date"))){
                    WHERE("lc.start_date >='"+params.get("start_date")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("end_date"))){
                    WHERE("lc.end_date <='"+params.get("end_date")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("provider_name"))){
                    WHERE("pi2.provider_name='"+params.get("provider_name")+"'");
                }

                if (!ObjectUtils.isEmpty(params.get("contract_amount"))){
                    WHERE("lc.contract_amount>='"+params.get("contract_amount")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("contract_amount2"))){
                    WHERE("lc.contract_amount<='"+params.get("contract_amount2")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("providerId"))){
                    WHERE("lc.labor_org_id='"+params.get("providerId")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("projectId"))){
                    WHERE("lc.p_id='"+params.get("projectId")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("empId"))){
                    WHERE("lc.contract_signatory='"+params.get("empId")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("approve_status"))){
                    WHERE("lc.approve_status='"+params.get("approve_status")+"'");
                }
            }
        }.toString();
    }

    //获取银行信息
    public String getBank(IPage<Map<String, Object>> page, Map<String, String> params){
        return new SQL(){
            {
                SELECT("*");
                FROM("bank");
                if (!ObjectUtils.isEmpty(params.get("bank_name"))){
                    WHERE("bank_name ='"+params.get("bank_name")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("account"))){
                    WHERE("account ='"+params.get("account")+"'");
                }
                if (!ObjectUtils.isEmpty(params.get("bank_of_deposit"))){
                    WHERE("bank_of_deposit='"+params.get("bank_of_deposit")+"'");
                }
            }
        }.toString();
    }
}
